<?php

namespace app\admin\controller\ucenter;

use app\admin\controller\Base;
use think\facade\Request;
use think\facade\View;
use app\common\model\Wechat as WechatModel;


class Member extends Base{
    protected $MemberModel;
    public function initialize()
    {
        parent::initialize(); 
        $this->model = new \app\admin\model\ucenter\Member();
        $list = WechatModel::select()->toArray();
        View::assign(['wx'=>$list]);
    }

    public function index(){
        if (Request::isPost()) {
            $keys = $this->request->post('keys', '', 'trim');
            $option = [
                'where' => [
                    ['realname|phone|username','like',"%".$keys."%"]
                ],
                'order' => 'id desc,create_time desc',
                'with' => ['wx'],
                'visible' => [
                    'wx' => ['name']  // 关联的模型名称要显示的字段名，默认展示全部
                ]
            ];
            $list = $this->model->loadList($option);

            if ($list['result'] == 'success'){
                $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['list'], 'count' => $list['page']['total']];
            }else{
                $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => [], 'count' => 0];
            }
            return $result;
        }
        return view();

    }
    
}